﻿Imports System.Data.SqlClient
Public Class FormCustomerEditor

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click















































































































































































































































































        If txtCustomerId.Text = "" Then
            Dim cn As New SqlConnection
            cn.ConnectionString = "server=.;uid=sa;pwd=123;database=SaleDb;"
            cn.Open()

            Dim cmd As New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "INSERT INTO	Customer VALUES(N'" & txtCustomerName.Text & "',N'" & txtPhone.Text & "',N'" & txtAddress.Text & "',N'" & txtEmail.Text & "',1)"

            cmd.ExecuteNonQuery()
            Me.DialogResult = Windows.Forms.DialogResult.OK

        Else
            Dim cn As New SqlConnection
            cn.ConnectionString = "server=.;uid=sa;pwd=123;database=SaleDb;"
            cn.Open()

            Dim cmd As New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "UPDATE Customer SET CustomerName=N'" & txtCustomerName.Text & "',PhoneNumber=N'" & txtPhone.Text & "',Cust_Address=N'" & txtAddress.Text & "' WHERE CustomerId=" & txtCustomerId.Text

            cmd.ExecuteNonQuery()
            Me.DialogResult = Windows.Forms.DialogResult.OK

        End If
       

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub TextBox1_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEmail.TextChanged

    End Sub
End Class